--
-- Author: ping.wang
-- Date: 2018-09-07 11:23:22
--
-- DynastyPromoteView
-- 会长本人被授予爵位的时候弹出的界面

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)
local IconRender = require("app.widget.renders.IconRender")
local string_split = string.split

ClassRef.VIEW_ROOT_RES = Res.DynastyPromoteScene

function ClassRef:init()
    self._ui.Button_close:addClickEventListener(function()
        self:closeView(false)
    end)
    self._ui["Panel/Button_close/name"]:setString(L("text_10200017"))
    self._ui.tips_2:setString(L("tips_1150028"))

    if self._data then
        local titleInfo = GD:queryPeerageById(self._data.titleId)
        if titleInfo then
            self._ui.tlt:setString(L"peerage9")
            self._ui.tips_1:setString(string.format(L("peerage8"),L(titleInfo.name)))
            if titleInfo.iconBig then
                self._ui.icon:loadTexture(Res.guildPositionIconPath..titleInfo.iconBig..".png")
            end

            local awardDatas = string_split(UD:parseClassText(titleInfo.rewardShow),";")

            local showGems = {}
            for i = 1, 3 do
                table.insert(showGems, self._ui["Panel/icon_"..i])
                if i <= #awardDatas then
                    local awardInfo = string_split(awardDatas[i],"|")
                    local icon = IconRender.create(self._ui["Panel/icon_"..i])
                    --需要设置为解锁的icon
                    icon:setVisible(true)
                    icon:setTipEnable(true)
                    icon:setData(
                        UD:parseLootToBagItem({type = tonumber(awardInfo[1]), id = tonumber(awardInfo[2]), num = tonumber(awardInfo[3])}))
                else
                    self._ui["Panel/icon_"..i]:setVisible(false)
                end

            end

            display.autoAdjustNodesPosX( self._ui["Panel"]:getContentSize().width, showGems, #awardDatas )
        end
    end
end

return ClassRef